#!../sl

apacheDirectory "/opt/apache" #

	-- Position-independent code (-fPIC) to generate .so apache module
flags.cpp "-fPIC -W -Wall -Ddebugging -g" :- rule DEBUG ! #
flags.cpp "-fPIC -pg" :- rule PROFILE ! #
flags.cpp "-fPIC -O3" #

flags.link "-lncurses -lpthread -lreadline -pg" :- rule PROFILE ! #
flags.link "-lncurses -lpthread -lreadline" #

:- import "%%/lib/maker.sl" #

:-	-- Creates the object file list from cpp names
	command.lines "ls *.cpp -1 | sed -e 's/\.cpp$/.o/'" .allobjs,
	list.remove .allobjs "libmod_sl.o" .o1,
	list.remove .o1 "dllmain.o" .objs,
	assert (OBJECT.FILES .objs) #


-- Compile singlog Interpreter Binary (Default Goal) --

make :- make "singlog" #

"sl", => "singlog" #


-- Link object files into binary --

	-- .o are compiled from their .cpp by default
	-- Header file dependencies are figured out automatically
.objs => "sl" :- OBJECT.FILES .objs #

process "sl" :- link "sl" #

"libmod_sl.so", => "apache" #


-- Build Apache Module --

"sl", "libmod_sl.cpp", => "libmod_sl.so" #

process "libmod_sl.so" :-
	flags.cpp .cppf,
	apacheDirectory .apacheDir,
	execute ("g++ -c " .cppf
		" `PKG_CONFIG_PATH=" .apacheDir "/lib/pkgconfig"
		" pkg-config apr-1 --cflags`"
		" libmod_sl.cpp -o libmod_sl.o"),
	OBJECT.FILES .objs,
	flags.link .linkf,
	execute ("g++ -fPIC -shared "
		.objs .linkf " libmod_sl.o -o libmod_sl.so"),
	execute (.apacheDir "/bin/apxs -i -a -n singlog libmod_sl.so") #


-- Remove Built Materials --

=> "clean" #

process "clean" :-
	OBJECT.FILES .objs,
	clean ("sl", "libmod_sl.o", "libmod_sl.so", .objs) #
